const express = require("express");
const path = require("path");

const cookieParser = require("cookie-parser");

const app = express();

app.use(cookieParser());

app.get("/", (req, res) => {
  // req.get(xxx) 获取请求头中 xxx 字段的值
  console.log(req.get("Accept"));
  console.log(req.get("Cookie"));
  console.log(req.cookies);
  res.send("hello");
});

// /abc -> /
app.get("/abc", (req, res) => {
  res.redirect("/");
});

app.get("/xxx", (req, res) => {
  // 写 cookie
  res.cookie("username", "张三");
  res.send("写入成功");
});

app.get("/html", (req, res) => {
  res.sendFile(path.resolve(__dirname, "./assets/demo.html"));
});

app.get("/png", (req, res) => {
  res.sendFile(path.resolve(__dirname, "./assets/a.png"));
});

app.listen(3000);
